package com.backend.modules.file.controller;

import com.backend.common.model.R;
import com.backend.modules.file.service.OssService;
import com.backend.modules.file.vo.OssTokenVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "文件上传", description = "文件上传相关接口")
@RestController
@RequestMapping("/v1/oss")
@RequiredArgsConstructor
public class OssController {

    private final OssService ossService;

    @Operation(summary = "获取上传凭证")
    @GetMapping("/token")
    public R<OssTokenVO> getToken(
            @Parameter(description = "上传目录，如：avatar/") @RequestParam String dir) {
        return R.ok(ossService.getToken(dir));
    }

    @Operation(summary = "删除文件")
    @DeleteMapping
    public R<Void> deleteFile(
            @Parameter(description = "文件路径") @RequestParam String objectName) {
        ossService.deleteFile(objectName);
        return R.ok();
    }
} 